/**
 * 
 */
package com.neiquan.secondhand.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

/** 
 * @author zhulang
 * @date 2016-6-22 下午03:22:25 
 * @descript 
 */

public class AutoAppointmentJob {

	private Logger logger = LoggerFactory.getLogger(AutoAppointmentJob.class);
		
	@Autowired
	public JdbcTemplate jdbcTemplate;
	
	public void excute(){
		logger.info("定时修改约伴状态......");
				
		String sql = "update appointment set appointStatus = " +
				"case when (endTime is not null and DATE_FORMAT(endTime,'%Y-%m-%d') >= DATE_FORMAT(NOW(),'%Y-%m-%d') and" +
				" DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(DepartureTime,'%Y-%m-%d')) then 1 " +
				"when (endTime is not null and DATE_FORMAT(NOW(),'%Y-%m-%d') > DATE_FORMAT(endTime,'%Y-%m-%d')) then 2 else 0 end ";
		//int result = systemRuntimeHibernateTemplate.bulkUpdate(sql);		执行的是SQL语句
		int result = jdbcTemplate.update(sql);
		
		logger.info("此次更新"+result+"条约伴信息......");
	}
	
}

